            
class BuildingController {
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only
    // accept POST requests
    def allowedMethods = [delete:'POST',
                          save:'POST',
                          update:'POST']

    def list = {
        if(!params.max)params.max = 10
        [ buildingList: Building.list( params ) ]
    }

    def show = {
        [ building : Building.get( params.id ) ]
    }

    def delete = {
        def building = Building.get( params.id )
        if(building) {
            building.delete()
            flash.message = "Building ${params.id} deleted."
            redirect(action:list)
        }
        else {
            flash.message = "Building not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def building = Building.get( params.id )

        if(!building) {
                flash.message = "Building not found with id ${params.id}"
                redirect(action:list)
        }
        else {
            return [ building : building ]
        }
    }

    def update = {
        def building = Building.get( params.id )
        if(building) {
             building.properties = params
            if(building.save()) {
                redirect(action:show,id:building.id)
            }
            else {
                render(view:'edit',model:[building:building])
            }
        }
        else {
            flash.message = "Building not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def building = new Building()
        building.properties = params
        return ['building':building]
    }

    def save = {
        def building = new Building()
        building.properties = params
        if(building.save()) {
            redirect(action:show,id:building.id)
        }
        else {
            render(view:'create',model:[building:building])
        }
    }

}